package cn.tedu.charging.order.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DelayDeclareConfiguration {
    private static final String DELAY_EX="delay_ex";
    private static final String DELAY_Q="delay_q";
    private static final String DLX_EX="dlx_ex";
    private static final String DLX_Q="dlx_q";
    private static final String DLX_RK="dlx_rk";
    //声明死信交换机
    @Bean
    public Exchange dlxEx(){
        return ExchangeBuilder.directExchange(DLX_EX).build();
    }
    //声明死信队列
    @Bean
    public Queue dlxQ(){
        return QueueBuilder.nonDurable(DLX_Q).build();
    }
    //声明死信绑定关系
    @Bean
    public Binding dlxBind(){
        return BindingBuilder.bind(dlxQ()).to(dlxEx()).with(DLX_RK).noargs();
    }
    //声明延迟交换机
    @Bean
    public Exchange delayEx(){
        return ExchangeBuilder.fanoutExchange(DELAY_EX).build();
    }
    //声明延迟队列
    //绑定死信交换机 绑定死信路由
    @Bean
    public Queue delayQ(){
        return QueueBuilder.nonDurable(DELAY_Q)
                .deadLetterExchange(DLX_EX)
                .deadLetterRoutingKey(DLX_RK).build();
    }
    //声明延迟组件绑定
    @Bean
    public Binding delayBind(){
        return BindingBuilder.bind(delayQ()).to(delayEx()).with("").noargs();
    }
}
